package main

import (
	"context"
	"log"
	"saasems/models"
	"saasems/services"
)

func UserInit() {
	userService := services.NewUserService()

	// 系统维护管理员创建用户
	sysAdmin, err := userService.CreateSystemUser(context.Background(), "sysadmin", "password", models.LevelSuperAdmin, []models.Permission{
		models.PermissionCreateUser,
		models.PermissionDeleteUser,
		models.PermissionEditUser,
	})
	if err != nil {
		log.Printf("创建系统管理员失败: %v", err)
		panic(err)
	}
	log.Printf("系统管理员创建成功: %v", sysAdmin)

	// 租户超级管理员创建用户
	tenantAdmin, err := userService.CreateTenantUser(context.Background(), "tenant1", "tenantadmin", "password", models.LevelAdmin, []models.Permission{
		models.PermissionCreateUser,
		models.PermissionEditUser,
	})
	if err != nil {
		log.Printf("创建租户管理员失败: %v", err)
		panic(err)
	}
	log.Printf("租户管理员创建成功: %v", tenantAdmin)

	// 验证权限
	hasPermission := userService.CheckPermission("tenantadmin", models.PermissionCreateUser)
	log.Printf("租户管理员是否有创建用户权限: %v", hasPermission)
}
